package com.example.liunanxin.lnx226ordering.model;



import com.example.liunanxin.lnx226ordering.beans.UserBean;
import com.example.liunanxin.lnx226ordering.iface.IsCollectListener;
import com.example.liunanxin.lnx226ordering.iface.IsCollectiface;
import com.example.liunanxin.lnx226ordering.retrofitservice.CollectService;
import com.example.liunanxin.lnx226ordering.url.Url;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class IsCollectModel implements IsCollectiface {
    private Retrofit retrofit;

    public IsCollectModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Url.USERURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void isCollect(int user_id, int shop_food_id, int flag, final IsCollectListener isCollectListener){
        final CollectService collectService=retrofit.create(CollectService.class);
        Call<UserBean> call=collectService.isCollected(user_id, shop_food_id, flag);
        call.enqueue(new Callback<UserBean>() {
            @Override
            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
                if (response.isSuccessful()&&response!=null)
                    isCollectListener.onRespose(response.body());
                else
                    isCollectListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<UserBean> call, Throwable t) {
                    isCollectListener.onFail(t.toString());
            }
        });

    }
}
